/**************************************************************************\
    Copyright Microsoft Corporation. All Rights Reserved.
\**************************************************************************/

namespace Conmigo.Widgets.TypeControls
{
    using System;
    using System.IO;
    using System.Windows;
    using System.Windows.Controls;
    using Standard;

    public partial class NameControl : UserControl
    {
        public NameControl()
        {
            InitializeComponent();
        }

        private void _SetUserTile(Stream stm)
        {
            ContactInfo view = (ContactInfo)DataContext;
            Stream disposable = view.UserTile.Value;
            Utility.SafeDispose(ref disposable);
            if (null != stm)
            {
                view.UserTile.Value = stm;
            }
            else
            {
                view.UserTile.Clear();
            }
        }

        private void _OnUserTileClick(object source, RoutedEventArgs e)
        {
            var ofn = new System.Windows.Forms.OpenFileDialog
            {
                Filter = "All Picture Files|*.BMP;*.GIF;*.JPEG;*.JPG;*.JPE;*.JFIF;*.PNG;*.TIF;*.TIFF;*.ICO|Bitmap Files (*.BMP)|*.BMP|GIF (*.GIF)|*.GIF|JPEG (*.JPEG;*.JPG;*.JPE;*.JFIF)|*.JPEG;*.JPG;*.JPE;*.JFIF|PNG (*.PNG)|*.PNG|TIFF (*.TIF;*.TIFF)|*.TIF;*.TIFF|ICO (*.ICO)|*.ICO|All Files|*",
                Title = "Select User Tile",
                InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures),
                Multiselect = false,
            };

            if (ofn.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                _SetUserTile(ofn.OpenFile());
            }
        }

        private void _OnUserTileClear(object source, RoutedEventArgs e)
        {
            _SetUserTile(null);
        }
    }
}